//
//  RFAImageViewingController.m
//  RFA Manager
//
//  Created by Torsten Kammer on 19.03.08.
//  Copyright 2008 Ferroequinologist.de. All rights reserved.
//

#import "RFAImageViewingController.h"
#import "RFAArchive.h"
#import "PropertyCategories.h"

@interface RFAImageViewingController ()

- (void)_generateImage;

@end

@implementation RFAImageViewingController

- (id)initWithArchiveEntry:(RFAArchiveEntry *)entry;
{
	if (![super initWithWindowNibName:@"TextureViewing"]) return nil;
	archiveEntry = entry;
	[archiveEntry addObserver:self forKeyPath:@"data" options:NSKeyValueObservingOptionNew context:NULL];
    
	return self;
}

@synthesize archiveEntry;
@synthesize image;

- (void)windowDidLoad
{
    [self _generateImage];
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqual:@"data"])
        [self _generateImage];
    else
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}


- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName;
{
	// It's got to be an em dash according to Apple HIG
	return [displayName stringByAppendingFormat:@" %C %@", 0x2014, archiveEntry.path.lastPathComponent];
}

- (NSUndoManager *)undoManagerForTextView:(NSTextView *)view
{
	return [self.document undoManager];
}

- (void)windowWillClose:(NSNotification *)notification;
{
	[self forceSave];
}

- (void)forceSave;
{
//	self.archiveEntry.contents = textView.string;
}

- (void)_generateImage
{
	self.image = self.archiveEntry.image;
    [self.window setContentSize:self.image.size];
}

@end
